import Cocoa

//var str = "Hello, playground"
//字典的创建
//初始化器
//var dict = Dictionary<String, Int>()  //初始化一个空的字典
////添加元素
//dict["name"] = 66
////修改元素
//dict.updateValue(16, forKey: "name")
//print(dict)
//
////删除元素
////dict.removeAll()
//dict.removeValue(forKey: "age")


//简写方法
//var dict2 = [String : Int]()

//字面量
//var dict3: Dictionary<String, Int> = ["name": 12]
//print(dict2)
//print(dict3)

//字面量创建字典  Any:可以代表任意数据类型
var dict: Dictionary<String, Any> = ["zhangsan": "12", "lisi": 34, "wangwu": "54"]
print(dict)
//获取字典的个数
print(dict.count)
//判断字典是否为空
print(dict.isEmpty)


//遍历字典
//for (key, value) in dict {
//    print("\(key), \(value)")
//}


//对字典中的key在遍历中进行排序
//for key in dict.keys.sorted() {
//    print("key is \(key)")
//}

//var array = [Int](1...10)
////判断数组中是否包含0
//print(array.contains(0))
////判断数组中是否有小于10的元素
//print(array.contains(where: {$0 < 10}))
////倒序排列数组元素
//for i in array.reversed() {
//    print(i)
//}


//合并两个字典
//var dict2 = ["a": 1, "b": 2]
//dict2.merge(["a": 3, "c": 4]) {(current, _) in current}
//print(dict2)
//
//dict2.merge(["a": 3, "c": 4]) { (_, new) in new }
//print(dict2)


//4.字典合并
var dict1 : [String :Any] = ["name":"why","age":10]
let dict2 : [String :Any] = ["height":1.83,"phone":"+86"]

for (key,value) in dict2 {
    dict1[key] = value
    print(dict1[key])
}








